extends Control

var state : BufferState : set = set_buffer_state

func set_buffer_state(value: BufferState):
	$VBoxContainer/Panel/Sprite2D.texture = value.icon
	state = value
	if state.show_duration:
		$VBoxContainer/Panel/DurationLabel.visible = true
		$VBoxContainer/Panel/DurationLabel.set_text(str(value.duration))
	if state.show_value:
		$VBoxContainer/HBoxContainer/Panel.visible = true
		$VBoxContainer/HBoxContainer/Panel/Label.set_text(str(value.value))
	$VBoxContainer/Panel.set_tooltip_text(value.tooltip_text_str)
		

func update_state(value, duration = 0):
	state.value = value
	state.duration = duration
	state.update_tooltip_text(value, duration)
	$VBoxContainer/HBoxContainer/Panel/Label.set_text(str(value))
	$VBoxContainer/Panel/DurationLabel.set_text(str(duration))
	$VBoxContainer/Panel.set_tooltip_text(state.tooltip_text_str)
	
func before_round(target):
	state.before_round(target)
	$VBoxContainer/Panel/DurationLabel.set_text(str(state.duration))
	state.update_tooltip_text(state.value, state.duration)
	$VBoxContainer/Panel.set_tooltip_text(state.tooltip_text_str)
	if state.show_duration and state.duration == 0:
		state.before_free(target)

		
func after_round(target):
	state.after_round(target)
	$VBoxContainer/Panel/DurationLabel.set_text(str(state.duration))
	state.update_tooltip_text(state.value, state.duration)
	$VBoxContainer/Panel.set_tooltip_text(state.tooltip_text_str)
	if state.show_duration and state.duration == 0:
		state.before_free(target)

